})
.map_err(|e| CliError::from_boxed(e, 1)));
- let source_id = SourceId::for_git(&url, reference.as_slice(), None);
+ let source_id = SourceId::for_git(&url, reference.as_slice());
let mut config = try!(Config::new(shell, None, None).map_err(|e| {
CliError::from_boxed(e, 1)
pub use self::registry::Registry;
pub use self::resolver::Resolve;
pub use self::shell::{Shell, MultiShell, ShellConfig};
-pub use self::source::{PathKind, RegistryKind};
-pub use self::source::{Source, SourceId, SourceMap, SourceSet, GitKind};
+pub use self::source::{Source, SourceId, SourceMap, SourceSet};
pub use self::summary::Summary;
pub mod source;
#[cfg(test)]
mod tests {
use super::{PackageId, CENTRAL_REPO};
- use core::source::{RegistryKind, SourceId};
+ use core::source::SourceId;
use util::ToUrl;
#[test]
fn invalid_version_handled_nicely() {
let loc = CENTRAL_REPO.to_url().unwrap();
- let repo = SourceId::new(RegistryKind, loc);
+ let repo = SourceId::for_registry(&loc);
assert!(PackageId::new("foo", "1.0", &repo).is_err());
assert!(PackageId::new("foo", "1", &repo).is_err());
}
#[deriving(Encodable, Decodable, Show, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
-pub enum SourceKind {
+enum SourceKind {
/// GitKind(<git reference>) represents a git repository
GitKind(String),
/// represents a local path
}
impl SourceId {
- pub fn new(kind: SourceKind, url: Url) -> SourceId {
+ fn new(kind: SourceKind, url: Url) -> SourceId {
SourceId {
inner: Arc::new(SourceIdInner {
kind: kind,
}
url.query = None;
let precise = mem::replace(&mut url.fragment, None);
- SourceId::for_git(&url, reference.as_slice(), precise)
+ SourceId::for_git(&url, reference.as_slice())
+ .with_precise(precise)
},
"registry" => {
let url = url.to_url().unwrap();
Ok(SourceId::new(PathKind, url))
}
- pub fn for_git(url: &Url, reference: &str, precise: Option<String>) -> SourceId {
+ pub fn for_git(url: &Url, reference: &str) -> SourceId {
SourceId::new(GitKind(reference.to_string()), url.clone())
- .with_precise(precise)
}
pub fn for_registry(url: &Url) -> SourceId {
}
pub fn get_url(&self) -> &Url { &self.inner.url }
- pub fn get_kind(&self) -> &SourceKind { &self.inner.kind }
pub fn is_path(&self) -> bool { self.inner.kind == PathKind }
pub fn is_registry(&self) -> bool { self.inner.kind == RegistryKind }
};
box PathSource::new(&path, self) as Box<Source>
},
- RegistryKind => box RegistrySource::new(self, config) as Box<Source+'a>,
+ RegistryKind => {
+ box RegistrySource::new(self, config) as Box<Source+'a>
+ }
}
}
self.inner.precise.as_ref().map(|s| s.as_slice())
}
+ pub fn git_reference(&self) -> Option<&str> {
+ match self.inner.kind {
+ GitKind(ref s) => Some(s.as_slice()),
+ _ => None,
+ }
+ }
+
pub fn with_precise(&self, v: Option<String>) -> SourceId {
SourceId {
inner: Arc::new(SourceIdInner {
use std::hash::sip::SipHasher;
use std::io::{fs, File, USER_RWX, BufferedReader};
-use core::{Package, Target, PathKind};
+use core::{Package, Target};
use util;
use util::{CargoResult, Fresh, Dirty, Freshness, internal, Require, profile};
// constant (which is the responsibility of the source)
let use_pkg = {
let doc = target.get_profile().is_doc();
- let path = match *pkg.get_summary().get_source_id().get_kind() {
- PathKind => true,
- _ => false,
- };
+ let path = pkg.get_summary().get_source_id().is_path();
doc || !path
};
use registry::{Registry, NewCrate, NewCrateDependency};
use core::source::Source;
-use core::{Package, MultiShell, SourceId, RegistryKind};
+use core::{Package, MultiShell, SourceId};
use core::manifest::ManifestMetadata;
use ops;
use sources::{PathSource, RegistrySource};
use std::mem;
use url::{mod, Url};
-use core::source::{Source, SourceId, GitKind};
+use core::source::{Source, SourceId};
use core::{Package, PackageId, Summary, Registry, Dependency};
use util::{CargoResult, Config, to_hex};
use sources::PathSource;
config: &'a mut Config<'b>) -> GitSource<'a, 'b> {
assert!(source_id.is_git(), "id is not git, id={}", source_id);
- let reference = match *source_id.get_kind() {
- GitKind(ref reference) => reference,
- _ => fail!("Not a git source; id={}", source_id)
+ let reference = match source_id.git_reference() {
+ Some(reference) => reference,
+ None => fail!("Not a git source; id={}", source_id),
};
let remote = GitRemote::new(source_id.get_url());
use semver;
use serialize::{Decodable, Decoder};
-use core::{SourceId, GitKind};
+use core::SourceId;
use core::manifest::{LibKind, Lib, Dylib, Profile, ManifestMetadata};
use core::{Summary, Manifest, Target, Dependency, PackageId};
use core::package_id::Metadata;
let new_source_id = match details.git {
Some(ref git) => {
- let kind = GitKind(reference.clone());
let loc = try!(git.as_slice().to_url().map_err(|e| {
human(e)
}));
- Some(SourceId::new(kind, loc))
+ Some(SourceId::for_git(&loc, reference.as_slice()))
}
None => {
details.path.as_ref().map(|path| {
use hamcrest::{assert_that, equal_to, contains};
-use cargo::core::source::{SourceId, RegistryKind, GitKind};
+use cargo::core::source::SourceId;
use cargo::core::{Dependency, PackageId, Summary, Registry};
use cargo::util::{CargoResult, ToUrl};
use cargo::core::resolver::{mod, ResolveEverything};
impl ToDep for &'static str {
fn to_dep(self) -> Dependency {
let url = "http://example.com".to_url().unwrap();
- let source_id = SourceId::new(RegistryKind, url);
+ let source_id = SourceId::for_registry(&url);
Dependency::parse(self, Some("1.0.0"), &source_id).unwrap()
}
}
fn registry_loc() -> SourceId {
let remote = "http://example.com".to_url().unwrap();
- SourceId::new(RegistryKind, remote)
+ SourceId::for_registry(&remote)
}
fn pkg(name: &str) -> Summary {
fn pkg_id_loc(name: &str, loc: &str) -> PackageId {
let remote = loc.to_url();
- let source_id = SourceId::new(GitKind("master".to_string()),
- remote.unwrap());
+ let source_id = SourceId::for_git(&remote.unwrap(), "master");
PackageId::new(name, "1.0.0", &source_id).unwrap()
}
fn dep(name: &str) -> Dependency { dep_req(name, "1.0.0") }
fn dep_req(name: &str, req: &str) -> Dependency {
let url = "http://example.com".to_url().unwrap();
- let source_id = SourceId::new(RegistryKind, url);
+ let source_id = SourceId::for_registry(&url);
Dependency::parse(name, Some(req), &source_id).unwrap()
}
fn dep_loc(name: &str, location: &str) -> Dependency {
let url = location.to_url().unwrap();
- let source_id = SourceId::new(GitKind("master".to_string()), url);
+ let source_id = SourceId::for_git(&url, "master");
Dependency::parse(name, Some("1.0.0"), &source_id).unwrap()
}